package com.gy.smart.life;

import android.widget.ImageView;
import android.widget.TextView;

import com.gy.smart.R;
import com.gy.smart.base.BaseActivity;
import com.gy.smart.base.BaseBean;
import com.gy.smart.life.bean.LifeDetailBean;
import com.gy.smart.util.RequestResultListener;
import com.gy.smart.util.Urls;
import com.nostra13.universalimageloader.core.ImageLoader;

import org.xutils.http.RequestParams;

/**
 * 作者：gy on 17/1/11
 * 说明：生活详情
 */
public class LifeDetailActivity extends BaseActivity {

    private TextView tvTitle, tvPhone, tvAddress, tvTime, tvStory;
    private ImageView img;
    private String life_id;
    private LifeDetailBean detailBean;

    @Override
    protected void initView() {
        setContentViewRes(R.layout.activity_life_detail);
        setTitleMsg("详情");
        img = (ImageView) findViewById(R.id.activity_life_detail_img);
        tvTitle = (TextView) findViewById(R.id.activity_life_detail_tv_title);
        tvPhone = (TextView) findViewById(R.id.activity_life_detail_tv_phone);
        tvAddress = (TextView) findViewById(R.id.activity_life_detail_tv_address);
        tvTime = (TextView) findViewById(R.id.activity_life_detail_tv_time);
        tvStory = (TextView) findViewById(R.id.activity_life_detail_tv_story);
    }

    @Override
    protected void initData() {
        life_id = getIntent().getStringExtra("life_id");
    }

    @Override
    protected void fillData() {
        super.fillData();
        requestData();
    }

    private void requestData() {
        showLoadDialog(1);
        RequestParams params = new RequestParams(Urls.url_life_detail);
        params.addParameter("life_id", life_id);
        postRequest(params, new RequestResultListener() {
            @Override
            public boolean onSuccess(BaseBean result) {
                if (result.status == 1) {
                    detailBean = gson.fromJson(result.data, LifeDetailBean.class);
                    tvTitle.setText(detailBean.title);
                    ImageLoader.getInstance().displayImage(detailBean.shop_img_url, img);
                    tvPhone.setText("电话：" + detailBean.tel);
                    tvAddress.setText("地址：" + detailBean.address);
                    tvTime.setText("营业时间：" + detailBean.open_time);
                    tvStory.setText("品牌故事：" + detailBean.brand_story);
                }
                return false;
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }
        });
    }
}
